/*
* @Author: majingyu
* @Date:   2017-05-06 11:07:04
* @Last Modified by:   jingyu.ma
* @Last Modified time: 2017-08-06 21:38:05
*/

import React from 'react';
import { connect } from 'react-redux';
import { changeShowStatus } from 'action/app.js';
import { searchAllServiceInfoAction,editCalssCheck } from 'action/service.js';
import 'css/sevicesList.less';

const seviceLiseData = (state) => {
    return {
        app:state.app,
        services: state.services
    }
}

class SeviceLise extends React.Component{
    constructor(props){
        super(props);
        this.props.changeShowStatus(false);
    }
    componentDidMount(){
        this.props.searchAllList();
    }
    gotoDetail(item){
        let historyPage = this.props.location.query.name;
        let historyType = this.props.location.query.type;
        this.props.editCalssCheck(item);
        if(historyPage == 'publish'){
            if(historyType == 'service')
                window.location.href = '#/publishService';
            if(historyType == 'skill')
                window.location.href = '#/publishSkill';
        }else if(historyPage == 'main'){
            window.location.href = '#/service';
        }

    }
    render(){
        let seviceList = this.props.services.servicesCalssifyList.list.map((services)=>{
            return(
                    <ul className="services-child" key={services.id}>
                        <li className="services-details" key={services.id} onClick={()=>{this.gotoDetail(services)}}>
                            {services.name}
                        </li>
                    </ul>
            );
        });
        return( 
            <div className="content">
                <div className="sevice-info" >
                    {seviceList}
                </div>
            </div>
        );
    }
}

let dispatchHandle = (dispatch, getState) => {
    return {
        searchAllList(){
           dispatch(searchAllServiceInfoAction())
        } ,
        changeShowStatus(status){
             dispatch(changeShowStatus(status));
        },
        editCalssCheck(item){
            dispatch(editCalssCheck(item));
        }
    }
    
}

let visibileService = connect(seviceLiseData, dispatchHandle)(SeviceLise);

export default visibileService;